#include<bits/stdc++.h>
#define ll long long
#define L x<<1
#define R x<<1|1
#define mid (l+r>>1)
#define lc L,l,mid
#define rc R,mid+1,r
#define Root 1,1,n
#define OK l>=Ll&&r<=Rr
#define rep(x,y,z) for(int x=(y);x<=(z);x++)
#define per(x,y,z) for(int x=(y);x>=(z);x--)
#define pb push_back
#define ull unsigned ll
#define e(x) for(int i=h[x],y=to[i];i;i=nxt[i],y=to[i])
#define E(x) for(auto y:p[x])
#define Pi pair<int,int>
#define ui unsigned int 
inline ll read(){ll s=0,w=1;char c=getchar();while(c<48||c>57) {if(c=='-') w=-1;c=getchar();}while(c>=48&&c<=57) s=(s<<1)+(s<<3)+c-48,c=getchar();return s*w;}
inline void pf(ll x){if(x<0) putchar('-'),x=-x;if(x>9)pf(x/10);putchar(x%10+48);}
const int N =1.5e3+5,M=1e6+5,inf=2147000000;
const ll llf=1e18,mod=1e9+7;
using namespace std;
int n,T;
string s;
string a[15];
int main(){
	freopen("brotherhood.in","r",stdin);
	freopen("brotherhood.out","w",stdout);
	n=read(),T=read();
	a[1]="0",a[2]="1";
	rep(i,3,n)a[i]=a[i-1]+a[i-2];
	int ln=a[n].length();
	while(T--){
		cin >>s;
		int len=s.length(),ans=0;
		rep(i,0,ln-len)ans+=a[n].substr(i,len)==s;
		pf(ans),putchar('\n');
	}
	return 0;
}
